{extend name="main" /}

{block name="body"}
{include file="breadcrumb" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class=" layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form" method="get">
                <input type="hidden" name="bcid" value="{:input('bcid')}"><!--保留当前位置的bcid参数-->
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="start_date" id="start_date" value="{:input('start_date')}" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" >
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">截止日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="end_date" id="end_date" value="{:input('end_date')}" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-card-body">
            <div class="btn-box">
                <button type="button" lay-on="deleteAll" class="layui-btn layui-btn-danger layui-btn-sm" title="">
                    删除选中
                </button>
            </div>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th width="25">
                            <div class="layui-form">
                                <input type="checkbox" name="selectAll" value="1" lay-filter="selectAll">
                            </div>
                        </th>
                        <th>ID</th>
                        <th>图片</th>
                        <th>存储位置</th>
                        <th width="15%">图片路径</th>
                        <th>应用</th>
                        <th>大小</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                {foreach name="list" item="vo"}
                <tr>
                    <td>
                        <div class="layui-form">
                            <input class="item-id" type="checkbox" name="id[]" value="{$vo.id}">
                        </div>
                    </td>
                    <td>{$vo.id}</td>
                    <td><img src="{$vo.url}" data-bigimg="{$vo.url}" class="xn_img" width="80"></td>
                    <td>{$vo.storage}</td>
                    <td>{$vo.url}</td>
                    <td>{$vo.app}</td>
                    <td>{$vo.file_size}</td>
                    <td>{$vo.create_time}</td>
                    <td>
                        <a href="{:url('delete',array('id'=>$vo['id']))}" title="删除记录的同时将删除图片文件，确定要删除吗？"
                           class="layui-btn layui-btn-danger layui-btn-sm xn_delete">
                            删除
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
            <div class="layui-row">
                <div class="pages">{$list|raw}</div>
                {include file="list_rows" /}
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        laydate.render({
            elem: '#start_date'
        });
        laydate.render({
            elem: '#end_date'
        });
    });

    //全选
    layui.use(function(){
        var form = layui.form;
        var layer = layui.layer;
        var util = layui.util;

        //全选
        form.on('checkbox(selectAll)', function(data){
            var child = $(".item-id");
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });

        //选中删除
        util.on('lay-on', {
            deleteAll:function () {
                var child = $(".item-id");
                var ids = [];
                child.each(function (index, item) {
                    if( item.checked === true ) {
                        ids.push(item.value)
                    }
                });
                if( ids.length === 0 ) {
                    layer.msg('请选中要删除的内容', {icon: 2});
                    return false;
                }
                layer.confirm('确定要删除所选吗？', {
                    btn: ['确定', '关闭'] //按钮
                }, function(){
                    var url = "{:url('delete')}";
                    $.post(url,{id:ids},function (data){
                        if( data.code === 1 ) {
                            layer.msg('删除成功', {icon: 1,time:1000}, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    },'json')
                });
            }
        });

    });
</script>
{/block}